package leetcode_800;

import java.util.ArrayList;
import java.util.List;

/**
 *@author 周杨
 *RemoveComments_722 给定代码块 返回去除注释后的代码
 *describe:AC 15%
 *2018年10月12日 下午3:56:46
 */
public class RemoveComments_722 {
	public List<String> removeComments(String[] source) {
		List<String> res = new ArrayList<String>();
		String tmp = "";
		boolean mulopen = false;
		for (int i = 0; i < source.length; i++) {
			for (int j = 0; j < source[i].length(); j++) {
				if (j < source[i].length() - 1 && source[i].charAt(j) == '/' && source[i].charAt(j + 1) == '/'
						&& !mulopen)
					break;
				else if (j < source[i].length() - 1 && source[i].charAt(j) == '/' && source[i].charAt(j + 1) == '*'
						&& !mulopen) {
					mulopen = true;
					j++;
				} else if (!mulopen)
					tmp += source[i].charAt(j);
				else if (j < source[i].length() - 1 && source[i].charAt(j) == '*' && source[i].charAt(j + 1) == '/'
						&& mulopen) {
					mulopen = false;
					j++;
				}

			}
			if (!mulopen && !tmp.equals("")) {
				res.add(tmp);
				tmp = "";
			}
		}
		return res;
        }
}
